from Exception_ import FgsException
from xmlrpclib import Fault, ProtocolError

class User(object):
    def __init__(self, portal, username):
        self.portal = portal
        self._proxy = portal._proxy
        self.name = username
        self.sid = None

    def login(self, password):
        try:
            self.sid = self._proxy.user.login(self.name, password)
        except Fault, f:
            raise FgsException("XmlRpc call faulted: %s" % f.faultString)
        except ProtocolError, p:
            raise FgsException("Transport error during XmlRpc call on %s: %s" % (p.errmsg, p.url))
